#ifndef CLIB_MODULE_H
#define CLIB_MODULE_H

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "clib_core.h"
#include "inc/clib_command.h"

extern clib_module_t *clib_mod[];

typedef enum clib_module_index_e
{
    clib_max_index
} clib_module_index_t;



struct clib_module_s {
    i32_t              index;
    i32_t              type;
    u64_t              weight;      
    const u08_t        *name;
    clib_command_t     *cmds;
    void               *ops;

    void             *(*create_lcore_conf)(i32_t socket_id);
    i32_t               (*init_lcore_conf)(clib_lcore_cycle_t *lcore_cycle, void *conf);

    void             *(*create_global_conf)(int socket_id);
    i32_t               (*init_global_conf)(clib_cycle_t *cycle, void *conf);

    i32_t               (*update_conf)(clib_cycle_t *cycle, char *data, u64_t timestamp);
    i32_t               (*register_handler)(clib_cycle_t *cycle);

    i32_t               (*init_master_thread)(clib_cycle_t *cycle);
    i32_t               (*init_helper_thread)(clib_cycle_t *cycle);
    i32_t               (*init_worker_thread)(clib_lcore_cycle_t *lcore_cycle);

    i32_t               (*exit_master_thread)(clib_cycle_t *cycle);
    i32_t               (*exit_helper_thread)(clib_cycle_t *cycle);
    i32_t               (*exit_worker_thread)(clib_lcore_cycle_t *lcore_cycle);

    i32_t               (*dump_module_stat)(clib_cycle_t *cycle);
    i32_t               (*free_lmain_conf)(void* gconf);
    i32_t               (*free_lcore_conf)(void* lconf);
    u08_t               *rely_on[];
};

//i32_t clib_conf_parse_entry(clib_conf_t* cf,clib_conf_entry_t *entry);

i32_t clib_conf_parse_json(clib_conf_t* cf,void *root);

clib_module_t* clib_get_module_by_name(clib_module_t** mod,int mod_num,const char* mod_name);

i32_t clib_load_modules_by_conf(clib_cycle_t *cycle,clib_core_conf_t *conf);

i32_t clib_load_modules_by_json(clib_cycle_t *cycle,void *root);

i32_t clib_modules_init(clib_cycle_t *cycle,clib_conf_t *conf,clib_module_t** mods, i32_t mod_cnt);

i32_t clib_modules_update_conf(clib_cycle_t *cycle,clib_module_t *mod,clib_conf_t* cf);

i32_t clib_load_modules(clib_cycle_t *cycle);

i32_t clib_module_create_global_conf(clib_cycle_t *cycle, clib_module_t *mod);

i32_t clib_module_create_lcore_conf(clib_cycle_t *cycle, clib_module_t *mod, i32_t index);

i32_t clib_module_config_by_conf(clib_cycle_t *cycle, clib_module_t *mod, clib_config_t *conf);

i32_t clib_modules_init_global_conf(clib_cycle_t *cycle, clib_module_t *mod);

i32_t clib_modules_init_lcore_conf(clib_cycle_t *cycle, clib_module_t *mod);

i32_t clib_modules_init_master_thread(clib_cycle_t *cycle, clib_module_t *mod);

i32_t clib_modules_init_worker_thread(clib_cycle_t *cycle, clib_module_t *mods);


#ifdef __cplusplus
}
#endif

#endif